<?php

  abstract class Ctype {

    /**
     * Check whether a character or string falls into a certain character class according to the current locale.
     * Returns true when every character provided in $string match $type check.
     *
     * @param String $variable The tested string.
     * @param const $type The type to match.
     * @return Boolean True on success or false on failure.
     *
     * @link http://fr.php.net/ctype
     * @link http://fr.php.net/manual/en/function.ctype-alnum.php
     * @link http://fr.php.net/manual/en/function.ctype-alpha.php
     * @link http://fr.php.net/manual/en/function.ctype-cntrl.php
     * @link http://fr.php.net/manual/en/function.ctype-digit.php
     * @link http://fr.php.net/manual/en/function.ctype-graph.php
     * @link http://fr.php.net/manual/en/function.ctype-lower.php
     * @link http://fr.php.net/manual/en/function.ctype-print.php
     * @link http://fr.php.net/manual/en/function.ctype-punct.php
     * @link http://fr.php.net/manual/en/function.ctype-space.php
     * @link http://fr.php.net/manual/en/function.ctype-upper.php
     * @link http://fr.php.net/manual/en/function.ctype-xdigit.php
     */
    public static function check(String $value, $type) {
      switch ($type) {
        case ICtype::ALPHANUMERIC :
          return new Boolean(ctype_alnum($value->toString()));

        case ICtype::ALPHABETIC :
          return new Boolean(ctype_alpha($value->toString()));

        case ICtype::CONTROL :
          return new Boolean(ctype_cntrl($value->toString()));

        case ICtype::DIGIT :
          return new Boolean(ctype_digit($value->toString()));

        case ICtype::GRAPH :
          return new Boolean(ctype_graph($value->toString()));

        case ICtype::LOWER :
          return new Boolean(ctype_lower($value->toString()));

        case ICtype::PRINTABLE :
          return new Boolean(ctype_print($value->toString()));

        case ICtype::PUNCTUATION :
          return new Boolean(ctype_punct($value->toString()));

        case ICtype::SPACE :
          return new Boolean(ctype_space($value->toString()));

        case ICtype::UPPER :
          return new Boolean(ctype_upper($value->toString()));

        case ICtype::HEXADECIMALDIGIT :
          return new Boolean(ctype_xdigit($value->toString()));
        default :
          return new Boolean(false);
      }
    }

  }

?>
